{-# LANGUAGE TemplateHaskell            #-}
{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Lambola.Stub
-- Copyright   :  (c) Stephen Tetley 2014
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Generate stub code for a datatype.
-- 
--------------------------------------------------------------------------------

module Lambola.Stub
   

  where

import Lambola.IDL.Syntax

import Language.Haskell.TH              -- package: template-haskell

import Data.Int
import Data.Word

-- Quasiquote looks highly desirable...

fieldName :: Identifier -> Name
fieldName = mkName


intType :: IntSpecifier -> Q Type
intType SIGNED_LONG_INT         = [t| Int32 |]
intType SIGNED_SHORT_INT        = [t| Int16 |]
intType UNSIGNED_LONG_INT       = [t| Word32 |]
intType UNSIGNED_SHORT_INT      = [t| Word16 |]


transType :: TypeSpec -> Q Type
transType (TyVoid)              = [t| () |]
transType (TyBoolean)           = [t| Bool |]
transType (TyInt spec)          = intType spec
transType (TyChar)              = [t| Char |]